using UnityEngine;
using UnityEngine.UI;

public class ChatItem : MonoBehaviour
{
    public RawImage icon;
    public Text content;
    float iconSize; 
    Texture2D m_iconSpr;
    void Awake()
    {
        iconSize = icon.GetComponent<RectTransform>().rect.width;
    }

    public void Init(Texture2D iconSpr, string content)
    {
        if (m_iconSpr)
            DestroyImmediate(m_iconSpr);
        m_iconSpr = iconSpr;

        if (iconSize <= 0)
            iconSize = icon.GetComponent<RectTransform>().rect.width;

        UnityFunctions.SetRawImage(icon, iconSpr, iconSize, true);// iconSpr;

        this.content.text = content;
    }

    void OnDestroy()
    {
        if (m_iconSpr)
            DestroyImmediate(m_iconSpr);

        //bool exist = NewTextureController.instance.OnDestroySpr(icon.sprite);
        //if (!exist)
        //{
        //    //Destroy(icon.sprite);
        //}
    }
}